package inl.resilienceManager.qmul.gemom;

import java.awt.Dimension;
import java.text.AttributedString;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.PieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.util.Rotation;

import resilienceManager.qmul.gemom.NSitem;

/** COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 * */

public class nsPie extends ApplicationFrame
{
	/*
	public nsPie(String paramString)
	  {
	    super(paramString);
	    PieDataset localPieDataset = createDataset();
	    JFreeChart localJFreeChart = createChart(localPieDataset);
	    ChartPanel localChartPanel = new ChartPanel(localJFreeChart);
	    setContentPane(localChartPanel);
	  }*/

	  public nsPie(String title) {
		super(title);
		// TODO Auto-generated constructor stub
	}



	private static PieDataset createDataset(NSitem[] items)
	  {
	    DefaultPieDataset localDefaultPieDataset = new DefaultPieDataset();
	    
	    double sum=0;
	    for(int i=0; i<items.length; i++)
	    {
	    	sum=sum+items[i].getSize();
	    }
	    
	    
	    
	    for(int i=0; i< items.length; i++)
	    {
	    	int id=i+1;
	    	String name="Item-"+id;
	    	double t= items[i].getSize();
	    	
	    	localDefaultPieDataset.setValue(name, new Double(t));
	    	
	    }

	    return localDefaultPieDataset;
	  }

	  private static JFreeChart createChart(PieDataset paramPieDataset)
	  {
	    JFreeChart localJFreeChart = ChartFactory.createPieChart3D("Items", paramPieDataset, true, true, false);
	    PiePlot3D localPiePlot3D = (PiePlot3D)localJFreeChart.getPlot();
	    localPiePlot3D.setStartAngle(300.0D);
	    localPiePlot3D.setDirection(Rotation.CLOCKWISE);
	    localPiePlot3D.setForegroundAlpha(0.5F);
	    localPiePlot3D.setNoDataMessage("No data to display");
	    localPiePlot3D.setLabelGenerator(new CustomLabelGenerator());
	    return localJFreeChart;
	  }

	  public static JPanel createPanel(NSitem[] items)
	  {
	    JFreeChart localJFreeChart = createChart(createDataset(items));
	    return new ChartPanel(localJFreeChart);
	  }


	  static class CustomLabelGenerator
	    implements PieSectionLabelGenerator
	  {
	    public String generateSectionLabel(PieDataset paramPieDataset, Comparable paramComparable)
	    {
	      String str = null;
	      if ((paramPieDataset != null) && (!(paramComparable.equals("PHP"))))
	        str = paramComparable.toString();
	      return str;
	    }

	    public AttributedString generateAttributedSectionLabel(PieDataset paramPieDataset, Comparable paramComparable)
	    {
	      return null;
	    }
	  }

}
